package ru.pachkun.home.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;

import ru.pachkun.home.util.DisplayedElementLocatorFactory;


public class PageManager {
	private WebDriver driver;
	public LoginPage loginPage;
	public InternalPage internalPage;
	public UserManagementPage userManagementPage;
	public UserProfilePage userProfilePage;
	public AddFilmPage addFilmPage;
	public FilmInfoPage filmInfoPage;

	public PageManager(WebDriver driver) {
		super();
		this.driver = driver;
	    loginPage = initElements(new LoginPage(this));
	    internalPage = initElements(new InternalPage(this));
	    userProfilePage = initElements(new UserProfilePage(this));
	    userManagementPage = initElements(new UserManagementPage(this));
	    addFilmPage = initElements(new AddFilmPage(this));
	    filmInfoPage = initElements(new FilmInfoPage(this));
	}

	private <T extends Page> T initElements(T page) {
		// PageFactory.initElements(driver, page);
		// PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10),
		// page);
		PageFactory.initElements(
				new DisplayedElementLocatorFactory(driver, 5), page);
		return page;
	}

	public WebDriver getDriver() {
		return driver;
	}
}
